package cn.wolfcode.trip.base.service.impl;


import cn.wolfcode.trip.base.domain.Information;
import cn.wolfcode.trip.base.domain.Reply;
import cn.wolfcode.trip.base.mapper.InformationMapper;
import cn.wolfcode.trip.base.mapper.ReplyMapper;
import cn.wolfcode.trip.base.service.IReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ReplyServiceImpl implements IReplyService {
    @Autowired
    private ReplyMapper replyMapper;
    @Autowired
    private InformationMapper informationMapper;


    @Override
    public void save(Reply reply) {
        Date date = new Date();
        reply.setReplyTime(date);
        replyMapper.insert(reply);
        //保存消息
        informationMapper.insertRelation(reply.getId(),2);
        informationMapper.insert(new Information(reply.getReplier(),reply.getByReply(),2,date));
    }

    @Override
    public Reply getReply(Long id) {
        return replyMapper.selectByPrimaryKey(id);
    }
}
